<template>
	<view class="content">
		<view>
			<el-input class="textarea" type="textarea" :rows="4" placeholder="请输入内容" v-model="textarea">
			</el-input>
		</view>
		<el-button class="btn" type="warning" @click="update">保存修改</el-button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				textarea: ""
			};
		},
		onLoad() {
			this.get()
		},
		methods: {
			// 新增
			async update() {
				return await uniCloud.callFunction({
					name: 'update',
					data: {
						tableName: 'we-notice',
						id: '60cafe2f4cb0900001f5502e',
						textarea: this.textarea
					}
				}).then((res) => {
					this.$notify({
						title: '提示',
						message: '修改成功',
						type: 'success'
					});
					return res.result.id
				}).catch((err) => {
					uni.showModal({
						content: `添加数据失败，错误信息为：${err.message}`,
						showCancel: false
					})
					console.error(err)
				})
			},
			// 获取列表
			async get() {
				return await uniCloud.callFunction({
					name: 'get',
					data: {
						tableName: 'we-notice', //要查询的表名
						pageIndex: 1, //第几页
						pageSize: 1 //每页的记录条数
					}
				}).then((res) => {
					console.log(res)
					this.textarea = res.result.data[0].textarea
					return res.result.data
				}).catch((err) => {
					uni.showModal({
						content: `查询失败，错误信息为：${err.message}`,
						showCancel: false
					})
					console.error(err)
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		padding: 40upx;
		width: 100%;

		.textarea {
			width: 60%;
		}
		.btn{
			margin-top: 40upx;
		}
	}
</style>
